package com.api;

import java.util.Random;
import java.util.Scanner;

public class RandomDemo {

    public static void main(String[] args) {

//        创建随机数生成器对象
        Random random = new Random();
//    [0,99]
        int i = random.nextInt(100) + 1;
//
//        System.out.println(i);

        Scanner scanner = new Scanner(System.in);

        int count = 0;

        while (true) {

            System.out.println("请输入你要猜的数字:");

            int num = scanner.nextInt();
            if (num > i) {
                System.out.println("猜大了!");
                count++;
            } else if (num < i) {
                System.out.println("猜小了!");
                count++;
            } else {
                System.out.println("恭喜你在猜了" + count + "后猜中了! ");

                break;
            }

        }
    }
}
